/**
 * @file        application.hpp
 * @brief       Defines the GTD application barebones.
 *
 * @author      Emre Turkay <emreturkay at gmail>
 * @date        May.31.2008
 *
 * Copyright Emre Turkay 2009
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file COPYRIGHT or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 */

#ifndef _APPLICATION_HPP_
#define _APPLICATION_HPP_

#include "gtd.hpp"

#include <boost/optional.hpp>
#include <boost/bind.hpp>

#include <exception>
#include <vector>
#include <string>

/*
 * Forward declarations.
 */

struct interface;

namespace gtd
{
    struct gtd;
    struct configuration;
}

/// gtdshell application interface.
struct application
{
    /**
     * @brief Constructs an application.
     * @arg intf            The console interface.
     * @arg backend         The task management backend.
     * @arg configuration   System specific configuration parameters.
     */
    application(interface& intf, gtd::gtd& backend,
                const gtd::configuration& conf);

    /// The main application loop.
    void run();

    /// Prompt the prompt char and next item in the queue.
    void prompt();

private:
    /// Tab complete the project name. @see reader::completer
    std::vector<std::string>
    list_complete(const std::vector<std::string>& args, bool complete);

    /// Tab complete the context name. @see reader::completer
    std::vector<std::string>
    context_complete(const std::vector<std::string>& args, bool complete);

private:
    /// When true, leaves the main loop.
    bool quit_;
    /// Reference to the console interface manager.
    interface& intf_;
    /// Reference to the task manager backend.
    gtd::gtd& backend_;
    /// Reference to the system specific configuration parameters.
    const gtd::configuration& config_;
    /// The current context.
    std::string context_;
    /// The current project id (if there is one).
    boost::optional<gtd::gtd::project_id> pid_;
};

#endif // _APPLICATION_HPP_
